<?php
namespace app\common\model\shop\ozon;

use think\admin\Model;
use think\facade\Cache;

/**
 * Undocumented class
 * @package app\common\model\shop
 * @author xuli
 * @DateTime 2024-10-25 10:49
 */
class OzonGoodsFeatureModel extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $name = 'shop_goods_feature_ozon';

    // 自动写入时间戳
    protected $autoWriteTimestamp = false;

    /**
     * 日志名称
     * @var string
     */
    protected $oplogName = 'Ozon属性特征';

    /**
     * 日志类型
     * @var string
     */
    protected $oplogType = 'Ozon属性特征管理';

    public static function getFeatureList($category_id)
    {
        $list = self::mq()->where(['category_id' => $category_id])->with(['featureValue' => function($featureValue) use ($category_id){
            $featureValue->field('id,value_id value,value name,feature_id');
            $featureValue->where('category_id', $category_id);
        }])->order('is_required desc')->select()->toArray();
        return $list;
    }

    public function featureValue(): \think\model\relation\HasMany
    {
        return $this->hasMany(OzonGoodsFeatureValueModel::class, 'feature_id', 'feature_id');
    }

}